<?php

include_once 'Answer_Patterns.php';

class Refactoring_Youtube extends Answer_Patterns {

   public function start($domDocument) {
      $result = "";
      $mount_tree = new Mount_DOM_tree();

      $search = $domDocument->getElementsByTagName('object');

      foreach ($search as $f) {
         if (ereg("^(.*)youtube(.*)$", strtolower($f->getElementsByTagName('embed')->item(0)->getAttribute('src')))) {
            $answer = '&LT;iframe width="' . $f->getAttribute('width') . '" height="' . $f->getAttribute('height') . '"'
                    . '<br> src="' . $f->getElementsByTagName('embed')->item(0)->getAttribute('src') . '" <br>'
                    . 'frameborder="0" allowfullscreen&GT; &LT;/iframe&GT;';
            
            $result .= parent::elementAnswerPatterns("&LT;$f->nodeName&GT;", $f->getLineNo(), "&LT;iframe&GT;");
            $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), $answer);
         }
      }
      
      if (!empty($result)) {
         $result = parent::titleAnswerPatterns("Integrar vídeos do Youtube") . $result;
      }

      return $result;
   }
}
?>